package com.nekonomics
package api.dto.response
import zio.json.*
import error.{AppError, UserError, TokenError, ValidationError}

/**
 * 一种简单的错误响应，只提供错误码和错误信息
 */
private case class ErrorRsp(code: Int, message: String) derives JsonCodec



object ErrorRsp {

  def fromAppError(appErr: AppError): ErrorRsp = ErrorRsp(appErr.errorCode, appErr.getMsg)
  def fromThrowable(e: Throwable): ErrorRsp = ErrorRsp(9999, e.getMessage)
  def of(code: Int, msg: String): ErrorRsp = ErrorRsp(code, msg)
  
}